package jdbc;

import java.nio.channels.SelectableChannel;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try(Connection connection= DBUtil.getconnection()){
            Statement statement=connection.createStatement();
            String sql="SELECT COUNT(*) count,c.name\n" +
                    "FROM class c\n" +
                    "JOIN student s ON c.id=s.class_id\n" +
                    "GROUP BY c.name";

            //SELECT s.name,s.gender,s.age,s.job,c.name,c.floor
            //FROM class c
            //JOIN student s ON c.id=s.class_id
            //WHERE c.name='1年级1班'
            ResultSet rs=statement.executeQuery(sql);
            while(rs.next()){
                int count=rs.getInt("count");
                String name=rs.getString("c.name");

                System.out.println("人数："+count+"，班级："+name);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
